package Lee_code;

import java.util.Arrays;

public class Lee_53_dp {
    public int maxSubArray(int[] nums) {
        int len = nums.length;

        //以dp为结尾是最大的子数组和
        int[] dp = new int[len];
        dp[0] = Math.max(0, nums[0]);
        for (int i=1; i<len; i++)
        {
            dp[i] = Math.max(nums[i], nums[i] + dp[i-1]);
        }
        return Arrays.stream(dp).max().getAsInt();
    }
}
